package cn.zxl.graduate.service.impl;

import cn.zxl.graduate.domain.Article;
import cn.zxl.graduate.mapper.ArticleMapper;
import cn.zxl.graduate.service.IArticleService;
import cn.zxl.graduate.service.IRedisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bo-feifei
 * @since 2021-11-02
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements IArticleService {

    @Autowired
    private IRedisService redisService;

    @Override
    public Integer watchNumAddByArtId(Long id) {
        Integer num = redisService.setWatchNumAdd(id);
        Article article = getById(id);
        article.setWatchNum(num.longValue());
        updateById(article);
        return num;
    }

    @Override
    public Integer likeNumAddByArtId(Long id) {
        Integer num = redisService.setLikeNumAdd(id);
        Article article = getById(id);
        article.setLikeNum(num.longValue());
        updateById(article);
        return num;
    }
}
